package com.gitee.wsl.markdown

import com.gitee.wsl.markdown.model.Document
import com.gitee.wsl.model.Model
import kotlinx.coroutines.CompletableJob

class Markwon(applicationJob: CompletableJob,
              private val userConfig: MarkwonConfiguration = MarkwonConfiguration(),
              ): Model<Markwon>(applicationJob){

     init {
         with(userConfig) {
             config.install(this@Markwon)
         }
     }

    /**
     * Method to parse markdown (without rendering)
     *
     * @param input markdown input to parse
     * @return parsed via commonmark-java `org.commonmark.node.Node`
     * @see .render
     * @since 3.0.0
     */
    fun parse(input: String): Document{
        TODO()
    }

    fun config(block: MarkwonConfiguration.() -> Unit) =
        Markwon(applicationJob, userConfig.clone().apply { block() }
            /*MarkwonConfiguration().apply {
                plusAssign(userConfig)
                block()
            }*/)



    companion object{

        fun create(applicationJob: CompletableJob,configFactory:MarkwonConfiguration.()->Unit):Markwon{
            val builder = MarkwonConfiguration()
            builder.configFactory()
            return Markwon(applicationJob,builder)
        }

    }
}

